/**
 * 11. 盛最多水的容器
 * https://leetcode-cn.com/problems/container-with-most-water/
 */

/**
 * @param {number[]} height
 * @return {number}
 */
function maxArea(height) {
  let left = 0;
  let right = height.length - 1;
  let max = 0;
  do {
    const area = Math.min(height[left], height[right]) * (right - left);
    if (area > max) {
      max = area;
    }
    if (height[left] > height[right]) {
      right -= 1;
    } else {
      left += 1;
    }
  } while (left < right);
  return max;
}

console.log(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]) === 49);
console.log(maxArea([1, 1]) === 1);
